<template>
    <div class="studentPortfolioBox">
        <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-tab-pane :label="titleName" name="schoolAlbum">
                <el-row v-if="!isDetailShow">
                    <el-col :span="24">
                        <div class="content clearFix">
                            <div class="imgList" v-for="item in pictureSchoolList.list" :key="item.id" @click="openPicture(item)">
                                <div class="imgWarp">
                                    <el-image :src="item.pictureurl | pictureUrl" style="height:150px" 
                                    :preview-src-list="getPictureUrl(pictureSchoolList.list)" :title="item.picturename">
                                        <div slot="placeholder" class="image-slot">
                                            加载中<span class="dot">...</span>
                                        </div>
                                        <div slot="error" class="image-slot">
                                            <i class="el-icon-picture-outline"></i>
                                        </div>
                                    </el-image>
                                </div>
                                <div class="imgName">
                                    <label>{{item.picturename}}</label>
                                </div>
                            </div>
                        </div>
                    </el-col>
                </el-row >
                <div class="block" v-if="!isDetailShow">
                    <el-pagination
                        background
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="currentPage"
                        :page-sizes="[12, 24, 30, 42]"
                        :page-size="pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="totals">
                    </el-pagination>
                </div >
                <ClassArticleDetail v-if="isDetailShow" :activeIndex="3" :album='picture' @closeDetails="closeDetails"></ClassArticleDetail>
            </el-tab-pane>
        </el-tabs>
    </div>
</template>

<script>
    import {
        pictureUrl
    } from '@/utils/filter'
    import {mapState} from 'vuex'
    import ClassArticleDetail from '@c/article/classArticleDetail'
    export default {
        props:['menuChangeN'],
        components:{
            ClassArticleDetail
        },
        computed:{
            ...mapState({
                userInfo: state => state.userModule.userInfo,
                otherUserInfo: state => state.userModule.otherUserInfo,
            })
        },
        watch:{
            menuChangeN:{
                handler(val){
                    this.menuActive(val)
                },
                deep: true
            }
        },
        created(){
        },
        beforeMount(){
            if(this.menuChangeN){
                this.menuActive(this.menuChangeN)
            }
        },
        mounted(){
            if(this.$route.query.junmpType == 2){
                 if(this.$route.query.dictype){
                     this.pictureSchool(this.$route.query.dictype)
                 }
            }
        },
        data() {
            return {
                picture: {},
                titleName: '',
                pictureSchoolList:{},
                activeName: 'schoolAlbum',
                currentPage:1,
                pageSize:12,
                totals: 0,
                src:require('../../assets/img/headportrait01.jpg'),
                isDetailShow: false,
                dictypeP:31,
            };
        },
        methods: {
            menuActive(val) {
                if(val.children){
                    val.children.map(item => {
                        if(item.routerTo == this.$route.path && item.jumpType == 2){
                            this.$nextTick(() =>{
                            this.isDetailShow = false
                            this.titleName = item.name
                            this.pictureSchool(item.id)
                            })
                        }
                    })
                }else{
                    this.isDetailShow = false
                    this.titleName = val.name
                    this.pictureSchool(val.id)
                }
            },
            closeDetails(){
                this.isDetailShow = false
            },
            openPicture(params) {
                if(this.otherUserInfo.userid && params.id){
                    if(this.otherUserInfo.userid != this.userInfo.id){
                        this.$store.dispatch('visitorAllModule/visitorAdd', {
                            fromuserid: this.otherUserInfo.userid,
                            visitorid: params.id,
                            type: 1
                        })
                    }
                }
                this.isDetailShow = true
                this.picture = params
            },
            getPictureUrl(params) {
                var arr = []
                params.map(item => {
                    arr.push(pictureUrl(item.pictureurl))
                })
                return arr
            },
             pictureSchool(params){
                this.dictypeP =  params
                this.$store.dispatch('photoalbumModule/pictureSchool',{
                    hisUserId:  this.otherUserInfo.userid || this.otherUserInfo.id || this.otherUserInfo.affiliatedId,
                    schoolid: this.otherUserInfo.xxdm,
                    classifyid: null,
                    dictype: params?params:this.dictypeP,
                    draft: 1,
                    limit: this.pageSize,
                    page: this.currentPage,
                    search: null,
                    sortType: 0,
                    userid: null,
                    yearandmonth: null
                }).then(res =>{
                    if(res.data.code == 200){
                        this.pictureSchoolList = res.data.result
                        this.totals =this.pictureSchoolList.total
                    }
                })
            },
            handleClick(tab, event) {
                // console.log(tab, event);
            },
            handleSizeChange(val) {
                this.pageSize = val
                this.pictureSchool(this.dictypeP)
            },
            handleCurrentChange(val) {
                this.currentPage = val
                this.pictureSchool(this.dictypeP)
            }
        }
    }
</script>

<style lang="scss" scoped>
.studentPortfolioBox{
    background-color: white;
    box-sizing: border-box;
    padding: 0 10px;
    min-height: 70vh;
    .imgList{
        float: left;
        margin-right: 10px;
        margin-bottom: 10px;
        .imgWarp{
            width: 190px;
            height: 190px;
        }
        .imgName{
            font-size: 14px;
            color: #303133;
            margin-top: 5px;
        }
    }
    .block{
        margin-top: 20px;
    }

    .clearFix::after{
        content: "";
        display: block;
        width: 100%;
        font-size: 0;
        clear: both;
    }
}
</style>